'''
Created on Jun 29, 2012

@author: shashank
This module uses thread builtin module of python 
'''
import thread
import time

def print_time(thread_name, delay):
    count = 0
    log = file("%s.log"%thread_name, 'w')
    while count <= 10:
        time.sleep(delay)
        count += 1
        log.write("%s:%s\n"%(thread_name, 
                         time.ctime(time.time())))
    else:
        log.close()

if __name__ == "__main__":
    print("In the main program")
    try:
        t1 = thread.start_new_thread(print_time, ("thread-%d"%1, 5))
        t2 = thread.start_new_thread(print_time, ("thread-%d"%2, 5))
    except Exception:
        print("Error in thread")
#    for x in range(10):
#        try:
#            thread.start_new_thread(print_time, ("thread-%d"%x, 5))
#        except Exception, exc:
#            print exc
    
    